<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="../include/admincontent.jsp" %>
<div id="location">当前位置：系统信息管理 > 组织架构管理</div>
<div id="sy_search" class=" f0f0f0" style="display: inline-block">
    <form id="advanceQueryParam">
        <div style="background-color: #f0f0f0">
            <div class="clearfix more_query_area">
                <div class="query_area_body clearfix">
                    <div class="record_item">
                        <div class="record_item">
                            <div class="label">部门编码:</div>
                            <div class="content">
                                <input type="text" name="code"/>
                            </div>
                        </div>
                    </div>
                    <div class="record_item">
                        <div class="record_item">
                            <div class="label">部门名称:</div>
                            <div class="content">
                                <input type="text" name="name"/>
                            </div>
                        </div>
                    </div>
                    <div class="record_item">
                        <div class="record_item">
                            <div class="label">部门全称:</div>
                            <div class="content">
                                <input type="text" name="fullname"/>
                            </div>
                        </div>
                    </div>
                    <%--                    <div class="query_area_footer clearfix">
                                            <div class="query_btns clearfix">
                                                <div class="query_btn left blue" id="searchbtn">
                                                    <span class="label">查询</span>
                                                </div>
                                                <div class="query_btn left gray" id="searchreset">
                                                    <span class="label">重置</span>
                                                </div>
                                            </div>
                                        </div>--%>
                    <div class="record_item">
                        <div class="toolbars">
                            <a id="searchbtn">
                                <em class="ico16 search_16"></em>
                                <span class="menu_span" title="查询">查询</span>
                            </a>
                            <a id="searchreset">
                                <em class="ico16 refresh_16"></em>
                                <span class="menu_span" title="重置">重置</span>
                            </a>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </form>
    <%-- <a width="60" id="combineQuery" class="font_size12 common_button combinedQuery">查询</a>--%>
</div>
<div id="Content" class="bg-content">
    <%--   <div class="clearfix common_toolbar_box">--%>
    <div class="toolbars" style="height:30px;white-space:nowrap;width:auto;margin-left: 20px;" totalwidth="314">
        <a id="dept_add">
            <em class="ico16 add_new"></em>
            <span class="menu_span">添加</span>
        </a>
        <a id="dept_edit">
            <em class="ico16 editor_16"></em>
            <span class="menu_span">编辑</span>
        </a>
        <a id="dept_del">
            <em class="ico16 del_16"></em>
            <span class="menu_span">删除</span>
        </a>
    </div>
    <%--    </div>--%>
</div>

<div style="overflow:hidden;">
    <div id="div_table" style="bottom: 0px">
        <table class="layui-hide" id="table" lay-filter="departmentTable"></table>
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function () {
        let documentHeight = $(document).height();
        let tableHeight = documentHeight - 90;
        layui.use('table', () => {
            let table = layui.table;
            table.render({
                id: 'table'
                , elem: '#table'
                , height: 'full'
                , url: '/SysAdmin/getDepartmentJson' //数据接口
                , title: '用户表'
                , page: true //开启分页
                , skin: 'line'
                , cols: [[ //表头
                    {type: 'checkbox', fixed: 'left'}
                    , {type: 'numbers', title: '序号', width: '10%', sort: true}
                    , {field: 'code', title: '部门编码', width: '30%', sort: true}
                    , {field: 'name', title: '部门名称', width: '30%'}
                    , {field: 'fullname', title: '部门全称', width: '30%'}
                ]]
                , done: (res, curr, count) => {
                    tableresize(diff, false)
                }
            });
            let reload = () => {
                table.reload('table', {
                    page: {
                        curr: 1,
                    }
                });
            }
            $("#searchbtn").on('click', () => {
                table.reload('table', {
                    where: {
                        code: $("input[name='code']").val(),
                        name: $("input[name='name']").val(),
                        fullname: $("input[name='fullname']").val(),
                    }, page: {
                        curr: 1
                    }
                })
            });
            //添加部门
            $('#dept_add').click(function () {
                openLayer('添加部门', '/SysAdmin/deptAdd', '700px', '90%');
                reload();
            });

            //修改部门
            $('#dept_edit').click(function () {

                    let url = "";
                    let chosendata = layui.table.checkStatus('table').data;
                    if (chosendata.length > 0) {

                        url = '/SysAdmin/deptAdd?code=' + chosendata[0].code
                            + '&name=' + chosendata[0].name
                            + '&fullname=' + chosendata[0].fullname;
                    }
                    LEditInfo('编辑部门', url, '700px', '90%');
                }
            );

            //删除部门
            $('#dept_del').click(function () {
                let chosendata = layui.table.checkStatus("table").data;
                if (chosendata.length === 0) {
                    layer.msg('请选择要执行该操作的信息', {icon: 7, time: 2000});
                } else {
                    $.ajax({
                        type: 'post',
                        dataType: "json",
                        url: '/SysAdmin/deptDel',
                        data: JSON.stringify(chosendata),
                        contentType: 'application/json;charset=utf-8',
                        error: function () {
                            layer.alert('服务器连接失败', {icon: 5, time: 5000});
                        },
                        success: function (msg) {
                            layer.msg(msg.msg, {icon:1, time: 2000})
                            reload();
                        }
                    });
                }
            });
            let origin = {};

            function tableresize(diff, resizeout = true) {
                let height3 = $("#div_table").height();
                let height4 = $(".layui-table-body.layui-table-main").height();
                let height5 = $(".layui-form.layui-border-box.layui-table-view").height();


                if (resizeout) {
                    $("#div_table").height(height3 - diff);
                }
                $(".layui-table-body.layui-table-main").height(height4 - diff);
                $(".layui-form.layui-border-box.layui-table-view").height(height5 - diff);
            }

            let diff;

            $("#combineQuery").on('click', (e) => {


                let style = $("#advanceQueryParam")[0].style;
                if (style.display === 'block') {
                    style.display = 'none';
                    diff = -origin.diff;
                } else {
                    style.display = 'block';
                    if (!origin.diff) {
                        origin.diff = document.documentElement.scrollHeight - document.documentElement.clientHeight;
                    }
                    diff = origin.diff;
                }
                tableresize(diff);

            });
        });

        $("#searchreset").on('click', (e) => {
            document.getElementById("advanceQueryParam").reset();
        });
    });

</script>
</body>
</html>